using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Verifications;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Battle
{
    class SkillLineSkill : InstantBattleSkill, IBattleSkill
    {
        public SkillLineSkill()
            : base(SkillTypecodeCollection.SKILL_02_ATTACK_ROW)
        {
        }

        public void apply(BattleActionHistory action, IBattleSkillAttack skillattack, Battler attacker, BattleTeam attacks, BattleTeam defenses)
        {
            Battler[] availableDefenses = defenses.getRowAppliers(attacker);

            if (availableDefenses.Length <= 0)
                return;

            int powerValue = attacker.getPowervalue();
            attacker.clearPowervalue();

            foreach (Battler defenser in availableDefenses)
            {
                if (!BattleFormular.skillAttackHit(attacker, defenser))
                {
                    BattleActionItemHistory actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_MISS);
                    actionItem.Attacker = (attacker.createHistory());
                    actionItem.Defenser = (defenser.createHistory());
                    continue;
                }
                else
                {
                    long hpValue = BattleFormular.skillAttackDamage(attacker, defenser, powerValue);
                    defenser.reduceHpPointValue(hpValue);

                    BattleActionItemHistory actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_SUCCEED);
                    actionItem.Attacker = (attacker.createHistory());
                    actionItem.Defenser = (defenser.createHistory());
                }
            }
        }

        public bool hasPowervalue()
        {
            return true;
        }
    }
}